﻿using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;

namespace lyAdmin.Common.Result
{
    /// <summary>
    /// Ajax返回数据操作类
    /// </summary>
    public class AjaxResultUtil
    {
        private static JsonResult RetResult(object Data,string msg,int len,string code)
        {
            AjaxResult ret = new AjaxResult();
            ret.Data = Data;
            ret.Code = code;
            ret.Length = len;
            ret.Msg = msg;
            return new JsonResult(ret);
        }
        /// <summary>
        /// 返回成功
        /// </summary>
        /// <returns>输出json格式</returns>
        public static JsonResult Success()
        {
            return RetResult(null, "操作成功", 0, "200");
        }
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="msg">返回信息</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Success(string msg)
        {
            return RetResult(null, msg, 0, "200");
        }
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="msg">返回信息</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Success(object Data, string msg)
        {
            return RetResult(Data, msg, 0, "200");
        }
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="msg">返回信息</param>
        /// <param name="len">数据行数</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Success(object Data, string msg, int len)
        {
            return RetResult(Data, msg, len, "200");
        }
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="len">数据行数</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Success(object Data, int len)
        {
            return RetResult(Data, "操作成功", len, "200");
        }
        /// <summary>
        /// 操作成功
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Success(object Data)
        {
            return RetResult(Data, "操作成功", 0, "200");
        }

        /// <summary>
        /// 操作失败
        /// </summary>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail()
        {
            return RetResult(null, "操作失败", 0, "100");
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="msg">返回信息</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail(string msg)
        {
            return RetResult(null, msg, 0, "100");
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="msg">返回信息</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail(object Data, string msg)
        {
            return RetResult(Data, msg, 0, "100");
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="msg">返回信息</param>
        /// <param name="len">数据行数</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail(object Data, string msg, int len)
        {
            return RetResult(Data, msg, len, "100");
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <param name="len">数据行数</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail(object Data, int len)
        {
            return RetResult(Data, "操作失败", len, "100");
        }
        /// <summary>
        /// 操作失败
        /// </summary>
        /// <param name="Data">返回数据</param>
        /// <returns>输出json格式</returns>
        public static JsonResult Fail(object Data)
        {
            return RetResult(Data, "操作失败", 0, "100");
        }
    }
}
